import Vue from 'vue'
import { mapState } from 'vuex'

export default () => {

	Vue.mixin({
		data () {
			return {}
		},
		beforeMount () {

		},
		activated () {
		},
		deactivated () {

		},
		destroyed () {

		},
		mounted () {
		},
		computed: {
			...mapState({
				currentUser: state => state.user.current || {},
				currentTime:state => state.user.currentTime
			}),
		},
		methods: {
			confirm (html, title) {
				return new Promise(resolve => {
					this.$confirm(
						html, title,
						{
							dangerouslyUseHTMLString: true,
							confirmButtonText: '确定',
							cancelButtonText: '取消',
							cancelButtonClass: 'el-button--primary is-plain',
							confirmButtonClass: 'el-button--medium  is-plain',
						}).then(async () => {
						resolve()
					}).catch(() => {})
				})
			},
			alert (html, title) {
				this.$alert(
					html,
					title,
					{
						dangerouslyUseHTMLString: true,
						confirmButtonText: '确定',
						confirmButtonClass: 'el-button--medium is-plain',
					},
				).catch(() => {})
			},
			transNumberString (val) {
				if (val === null || val === undefined) {
					val = ''
				} else {
					val += ''
				}
				return val
			},
			// validateArray (array = []) {
			// 	for (let v of array) {
			// 		if (!this.validate(...v)) {
			// 			return false
			// 		}
			// 	}
			// 	return true
			// },
			delay (func, wait = 1000, ...args) {
				return new Promise((resolve => {
					setTimeout(async () => {
						await func()
						resolve()
					}, parseInt(wait) || 0, ...args)
				}))
			},
			//
			// validate (bool, msg) {
			// 	if (!bool) {
			// 		console.error(msg)
			// 		return false
			// 	} else {
			// 		return true
			// 	}
			// },
			//
			// async tc (func, catch_func, final) {
			// 	try {
			// 		if (func) {
			// 			if (func instanceof Promise) {
			// 				await func()
			// 			} else if (func instanceof Function) {
			// 				func()
			// 			}
			// 		}
			// 	} catch (e) {
			// 		console.log(this.$vnode.tag, e)
			// 		if (catch_func) {
			//
			// 			if (catch_func instanceof Promise) {
			// 				await catch_func(e)
			// 			} else if (catch_func instanceof Function) {
			// 				catch_func(e)
			// 			}
			// 		}
			// 	} finally {
			// 		await this.delay(() => {
			// 			// this.$toast.clear()
			// 		}, 500)
			// 		if (final) {
			// 			if (final instanceof Promise) {
			// 				await final()
			// 			} else if (final instanceof Function) {
			// 				final()
			// 			}
			// 		}
			//
			// 	}
			// },
		},
	})
}
